

import lejos.nxt.*;
import lejos.robotics.navigation.DifferentialPilot;


public class BumpAndGo {

	static double SIDE_SIZE = 40.0;
	static double WHEEL_DIAMETER = 5.6f;
	static double AXIS_LENGTH = 5.6f;
	
	public static void main (String[] args) throws Exception {
		
		// Navigator:
		DifferentialPilot navigator = new DifferentialPilot(WHEEL_DIAMETER, AXIS_LENGTH, Motor.A, Motor.C);
		
		// Instantiating Sensor ports:
		TouchSensor touchFront	= new TouchSensor(SensorPort.S1);
		TouchSensor touchBack 	= new TouchSensor(SensorPort.S2);
		
		// Calibrate sensors if needed:

		navigator.forward();
		
		while (true)
		{
			if (Button.ESCAPE.isPressed()) {
				break;
			}
			
			if (touchFront.isPressed() || touchBack.isPressed()) {
				navigator.stop();
				navigator.travel(-10);
				
				// Calculate random angle:
				int angle = 45 + (int)(90 * Math.random());
				
				navigator.rotate(angle);
				navigator.forward();
			}
		}

	}
}
